package com.zjjk.transfer.source.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.zjjk.transfer.source.entity.SourceRecvRefundOrder;
import com.zjjk.transfer.source.mapper.SourceRecvRefundOrderMapper;
import com.zjjk.transfer.source.service.SourceRecvRefundOrderService;
import com.zjjk.transfer.source.param.SourceRecvRefundOrderPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 退款记录表 服务实现类
 *
 * @author xuziyang
 * @since 2021-03-26
 */
@Slf4j
@Service
@DS("source")
public class SourceRecvRefundOrderServiceImpl extends BaseServiceImpl<SourceRecvRefundOrderMapper, SourceRecvRefundOrder> implements SourceRecvRefundOrderService {

    @Autowired
    private SourceRecvRefundOrderMapper sourceRecvRefundOrderMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSourceRecvRefundOrder(SourceRecvRefundOrder sourceRecvRefundOrder) throws Exception {
        return super.save(sourceRecvRefundOrder);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSourceRecvRefundOrder(SourceRecvRefundOrder sourceRecvRefundOrder) throws Exception {
        return super.updateById(sourceRecvRefundOrder);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSourceRecvRefundOrder(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SourceRecvRefundOrder> getSourceRecvRefundOrderPageList(SourceRecvRefundOrderPageParam sourceRecvRefundOrderPageParam) throws Exception {
        Page<SourceRecvRefundOrder> page = new PageInfo<>(sourceRecvRefundOrderPageParam, OrderItem.desc(getLambdaColumn(SourceRecvRefundOrder::getCreateTime)));
        LambdaQueryWrapper<SourceRecvRefundOrder> wrapper = new LambdaQueryWrapper<>();
        IPage<SourceRecvRefundOrder> iPage = sourceRecvRefundOrderMapper.selectPage(page, wrapper);
        return new Paging<SourceRecvRefundOrder>(iPage);
    }

}
